<?php

namespace App\Http\Controllers\Back;

use App\Model\Comment;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;

class CommentController extends Controller
{

    private function leftBar() {
        return [
            'title' => '评论管理',
            'list'  => [
                [
                    'title' => '评论列表',
                    'type' => 'comment_list',
                    'url' => url('back/comment'),
                ],
            ]
        ];
    }

    /**
     * @param Request $request
     * czs
     */
    public function __construct(Request $request){
        $this->request = $request;
        $this->limit = config('config.pageLimit');
        $leftBarArr = $this->leftBar();
        view()->share(['title' => $leftBarArr['title'],'list'=>$leftBarArr['list'],'limit'=>$this->limit]);
    }

    /**
     * Display a listing of the resource.
     * 评论列表
     * @return \Illuminate\Http\Response
     * czs
     */
    public function index()
    {
        $keyWord = $this->request->input('keyword');
        $res = Comment::getList($keyWord,$this->limit)->getData();
        $this->request->flash();
        return view('back/comment/index')
            ->with('res',$res)
            ->with('titleType','comment_list');
    }

    /**
     * Remove the specified resource from storage.
     * 删除
     * czs
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function delete($id)
    {
        $del = Comment::deleteLine($id);
        return $del->getResult();
    }

    /**
     * 评论详情
     * czs
     */
    public function view($id)
    {
        $res = Comment::view($id)->getData();
        return view('back/comment/view')
            ->with('res',$res);
    }
}
